/*
 * @Author: FMC
 * @Date: 2024-07-10 20:25:58
 * @LastEditors: FMC
 * @LastEditTime: 2024-07-11 01:00:33
 * @FilePath: \three-run-game\src\stores\useGame.js
 * @Description: 
 */
import { create } from "zustand";
import { subscribeWithSelector } from "zustand/middleware";

const useBearStore = create(
  subscribeWithSelector((set) => ({
    //路程
    blockCount: 15,
    //关卡种子
    blockSeed:0,
    /**
     * 游戏状态
     */
    gameState: "ready",
    startTime: 0,
    endTime: 0,

    start: () => {
      set((state) => {
        if (state.gameState === "ready") {
          return { gameState: "playing", startTime: Date.now() };
        }
        // 如果不就行更改操作就返回一个{}。否则会报错
        return {};
      });
    },
    reStart: () => {
      set((state) => {
        if (state.gameState === "playing" || state.gameState === "ended") {
          return { gameState: "ready", endTime: 0, startTime: 0,blockSeed:Math.random() };
        }
        return {};
      });
    },
    end: () => {
      set((state) => {
        if (state.gameState === "playing") {
          // console.log('state',state)
          return { gameState: "ended", endTime: Date.now() };
        }
        return {};
      });
    },
  }))
);
export default useBearStore;




